package com.zznj.xzjc.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.zznj.xzjc.R;
import com.zznj.xzjc.bean.FileModel;
import com.zznj.xzjc.fragment.FragmentActivityFile;

import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTransaction;

@SuppressLint("NewApi")
public class ActivityFile extends FragmentActivity implements FragmentActivityFile.OnFileChoosedListener {
	private FragmentTransaction mFragTran;
	private ImageView tv_back;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gyss_activity_file);
		initView();
	}

	private void initView() {
		tv_back = (ImageView) findViewById(R.id.activity_file_back);
		FragmentActivityFile fragmentFile = new FragmentActivityFile();
		Bundle bundle = new Bundle();
		fragmentFile.setArguments(bundle);
		mFragTran = getSupportFragmentManager().beginTransaction();
		mFragTran.setCustomAnimations(R.anim.tcyz_slide_in_from_right, R.anim.tcyz_slide_out_to_left, R.anim.tcyz_slide_in_from_left, R.anim.tcyz_slide_out_to_right);
		mFragTran.add(R.id.activity_file_frame, fragmentFile);
		mFragTran.commit();

		tv_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (tv_back.getId() == v.getId()) {
					if (getSupportFragmentManager().getBackStackEntryCount() != 0) {
						getSupportFragmentManager().popBackStack();
					} else {
						finish();
					}
				}
			}
		});
	}

	@Override
	public void onChoosedListener(FileModel file) {
		if (file.isFileFolder()) {
			FragmentActivityFile _FragmentDatum = new FragmentActivityFile();
			Bundle bundle = new Bundle();
			bundle.putString("filepath", file.getFilePath());
			_FragmentDatum.setArguments(bundle);
			FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
			ft.setCustomAnimations(R.anim.tcyz_slide_in_from_right, R.anim.tcyz_slide_out_to_left, R.anim.tcyz_slide_in_from_left, R.anim.tcyz_slide_out_to_right);
			ft.replace(R.id.activity_file_frame, _FragmentDatum);
			ft.addToBackStack(null);
			ft.commit();
		} else {
			Intent intent = new Intent();
			intent.putExtra("filePath", file.getFilePath());
			setResult(RESULT_OK, intent);
			finish();
		}
	}
}
